/**
 * Created by George on 2018/1/28.
 * frame route
 */
// frameRouter.js
"use strict";
define(['angular', 'require', 'angular-ui-route', 'mainCtrl'], function (angular, require, route, mainCtrl) {

    Date.prototype.format = function (format) {
        var o = {
            "M+": this.getMonth() + 1, //month
            "d+": this.getDate(),    //day
            "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12,
            "H+": this.getHours(),   //hour
            "m+": this.getMinutes(), //minute
            "s+": this.getSeconds(), //second
            "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
            "S": this.getMilliseconds() //millisecond
        };
        if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
            (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1,
                RegExp.$1.length == 1 ? o[k] :
                    ("00" + o[k]).substr(("" + o[k]).length));
        return format;
    };

    /**
     var appNote = angular.module('appNote', ['ngRoute']);

     appNote.config(['$routeProvider', '$controllerProvider',
     function ($routeProvider, $controllerProvider) {
            $routeProvider
                .when('/activity', {
                    templateUrl: 'views/activity.html',
                    controller: 'activityCtrl',
                    resolve: {
                        delay: ctrlRegister('activityCtrl', ['activityCtrl'])
                    }
                })
                .when('/dues', {
                    templateUrl: 'views/dues.html',
                    controller: 'duesCtrl',
                    resolve: {
                        delay: ctrlRegister('duesCtrl', ['duesCtrl'])
                    }
                })
                .when('/user', {
                    templateUrl: 'views/user.html',
                    controller: 'userCtrl',
                    resolve: {
                        delay: ctrlRegister('userCtrl', ['userCtrl'])
                    }
                })
                .when('/user/edit', {
                    templateUrl: 'views/editUser.html',
                    controller: 'editUserCtrl',
                    resolve: {
                        delay: ctrlRegister('editUserCtrl', ['editUserCtrl'])
                    }
                })
                .when('/user/edit/*', {
                    templateUrl: 'views/editUser.html',
                    controller: 'editUserCtrl',
                    resolve: {
                        delay: ctrlRegister('editUserCtrl', ['editUserCtrl'])
                    }
                })
                .otherwise({
                    redirectTo: '/user'
                });

            function ctrlRegister(ctrlName, ctrlModule) {
                return function ($q) {
                    var defer = $q.defer();
                    require(ctrlModule, function (controller) {
                        $controllerProvider.register(ctrlName, controller);
                        defer.resolve();
                    });
                    return defer.promise;
                }
            }
        }
     ]);
     **/

    var appNote = angular.module('appNote', ['ui.router']);
    appNote.run(['$rootScope', '$state', '$stateParams', function ($rootScope, $state, $stateParams) {
        $rootScope.$state = $state;
        $rootScope.$stateParams = $stateParams;
    }]).config(['$stateProvider', '$urlRouterProvider', '$controllerProvider', function ($stateProvider, $urlRouterProvider, $controllerProvider) {
        $urlRouterProvider.when("", "/user");
        $urlRouterProvider.otherwise("/user");
        $stateProvider.state("activity", {
            url: '/activity',
            templateUrl: 'views/activity/activity.html',
            controller: 'activityCtrl',
            resolve: {
                delay: ctrlRegister('activityCtrl', ['activityCtrl'])
            }
        }).state("editActivity", {
            url: '/activity/edit/{activityId:.*}',
            templateUrl: 'views/activity/editActivity.html',
            controller: 'editActivityCtrl',
            resolve: {
                delay: ctrlRegister('editActivityCtrl', ['editActivityCtrl'])
            }
        }).state("createActivity", {
            url: '/activity/create',
            templateUrl: 'views/activity/createActivity.html',
            controller: 'createActivityCtrl',
            resolve: {
                delay: ctrlRegister('createActivityCtrl', ['createActivityCtrl'])
            }
        }).state("dues", {
            url: '/dues',
            templateUrl: 'views/dues/dues.html',
            controller: 'duesCtrl',
            resolve: {
                delay: ctrlRegister('duesCtrl', ['duesCtrl'])
            }
        }).state("editDues", {
            url: '/dues/edit/{duesId:.*}',
            templateUrl: 'views/dues/editDues.html',
            controller: 'editDuesCtrl',
            resolve: {
                delay: ctrlRegister('editDuesCtrl', ['editDuesCtrl'])
            }
        }).state("createDues", {
            url: '/dues/create',
            templateUrl: 'views/dues/createDues.html',
            controller: 'createDuesCtrl',
            resolve: {
                delay: ctrlRegister('createDuesCtrl', ['createDuesCtrl'])
            }
        }).state("user", {
            url: '/user',
            templateUrl: 'views/user/user.html',
            controller: 'userCtrl',
            resolve: {
                delay: ctrlRegister('userCtrl', ['userCtrl'])
            }
        }).state("editUser", {
            url: '/user/edit/{userId:.*}',
            templateUrl: 'views/user/editUser.html',
            controller: 'editUserCtrl',
            resolve: {
                delay: ctrlRegister('editUserCtrl', ['editUserCtrl'])
            }
        }).state("createUser", {
            url: '/user/create',
            templateUrl: 'views/user/createUser.html',
            controller: 'createUserCtrl',
            resolve: {
                delay: ctrlRegister('createUserCtrl', ['createUserCtrl'])
            }
        }).state("note", {
            url: '/note',
            templateUrl: 'views/note/note.html',
            controller: 'noteCtrl',
            resolve: {
                delay: ctrlRegister('noteCtrl', ['noteCtrl'])
            }
        }).state("createNote", {
            url: '/basketballfire/create',
            templateUrl: 'views/note/createNote.html',
            controller: 'createNoteCtrl',
            resolve: {
                delay: ctrlRegister('createNoteCtrl', ['createNoteCtrl'])
            }
        }).state("editNote", {
            url: '/basketballfire/edit/{noteId:.*}',
            templateUrl: 'views/note/editNote.html',
            controller: 'editNoteCtrl',
            resolve: {
                delay: ctrlRegister('editNoteCtrl', ['editNoteCtrl'])
            }
        });

        function ctrlRegister(ctrlName, ctrlModule) {
            return function ($q) {
                var defer = $q.defer();
                require(ctrlModule, function (controller) {
                    $controllerProvider.register(ctrlName, controller);
                    defer.resolve();
                });
                return defer.promise;
            }
        }

    }]);

    appNote.controller("mainCtrl", mainCtrl);
    appNote.filter('trustHtml', function ($sce) {

        return function (input) {
            return $sce.trustAsHtml(input);
        }

    });

    return appNote;
});